André Leite, Cristiano Ferraz, and Raydonal Ospina

André Leite (leite@castlab.org)
Cristiano Ferraz (cferraz@castlab.org)
Raydonal Ospina (raydonal@castlab.org)
Test
Test
RShinyTest
Ferraz & Mecatti
Test
Definition
the practice of obtaining information or input into a task or project by enlisting the services of a large number of people, either paid or unpaid, typically via the Internet.






leaflettidyverseRColorBrewerrmarkdownrgdalrgeossp vs. sfset.seed(123)
library(rgdal)
library(raster)
library(rgeos)
library(tidyverse)
uruguay <- getData("GADM", country = "URY", level = 0)
uruguay_projected <- spTransform(uruguay, CRS("+init=epsg:3857"))
forest_projected <- uruguay_projected %>%
spsample(200, type = "random") %>%
# build random poisson buffers around them
gBuffer(width = 4000 * rpois(length(.), 3), byid = TRUE) %>%
gEnvelope(byid = TRUE) %>% # take their envelope
gUnaryUnion()
forest_projected <- gIntersection(uruguay_projected, forest_projected)
forest <- spTransform(forest_projected, CRSobj = crs(uruguay))buffers_projected <- uruguay_projected %>%
spsample(10, type = "random") %>%
gBuffer(width = 30000, byid = TRUE)
buffers <- spTransform(buffers_projected, CRSobj = crs(uruguay))
# Intersect the buffers with the forest and plot the result
intersect_projected <- gIntersection(forest_projected,
buffers_projected,
byid = TRUE
)
intersect <- spTransform(intersect_projected, CRSobj = crs(uruguay))
# Compute the proportion of forested areas within each buffer
proportion <- gArea(intersect_projected, byid = TRUE) /
gArea(buffers_projected, byid = TRUE)
intersect.spdf <- SpatialPolygonsDataFrame(
intersect,
data.frame(Proportion = proportion)
)set.seed(123)
library(rgdal)
library(raster)
library(rgeos)
library(tidyverse)
colombia <- getData("GADM", country = "COL", level = 0)
colombia_projected <- spTransform(colombia, CRS("+init=epsg:3857"))
forest_projected <- colombia_projected %>%
spsample(400, type = "random") %>%
# build random poisson buffers around them
gBuffer(width = 4000 * rpois(length(.), 3), byid = TRUE) %>%
gEnvelope(byid = TRUE) %>% # take their envelope
gUnaryUnion()
forest_projected <- gIntersection(colombia_projected, forest_projected)
forest <- spTransform(forest_projected, CRSobj = crs(uruguay))buffers_projected <- colombia_projected %>%
spsample(20, type = "random") %>%
gBuffer(width = 30000, byid = TRUE)
buffers <- spTransform(buffers_projected, CRSobj = crs(colombia))
# Intersect the buffers with the forest and plot the result
intersect_projected <- gIntersection(forest_projected,
buffers_projected,
byid = TRUE
)
intersect <- spTransform(intersect_projected, CRSobj = crs(colombia))
# Compute the proportion of forested areas within each buffer
intersections <- gArea(intersect_projected, byid = TRUE) %>%
tibble(ID = names(.), Area_intersection = .) %>%
separate(ID, into = c("Grid", "ID"))
buffers_areas <- gArea(buffers_projected, byid = TRUE) %>% tibble(ID = names(.), Area_buffers = .)
proportion <- left_join(intersections, buffers_areas, by = "ID") %>%
mutate(proportion = Area_intersection / Area_buffers, label = paste0(round(100 * proportion, 1), "%")) %>%
as.data.frame()
row.names(proportion) <- row.names(intersect)
intersect.spdf <- SpatialPolygonsDataFrame(intersect, proportion)
Shiny is an R package that makes it easy to build interactive web apps straight from R. You can host standalone apps on a webpage or embed them in
R Markdowndocuments or build dashboards. You can also extend your Shiny apps with CSS themes, htmlwidgets, and JavaScript actions.

Server
UI
# Use a fluid Bootstrap layout
fluidPage(
# Give the page a title
titlePanel("Telephones by region"),
# Generate a row with a sidebar
sidebarLayout(
# Define the sidebar with one input
sidebarPanel(
selectInput("region", "Region:", choices=colnames(WorldPhones)),
hr(),
helpText("Data from AT&T (1961) The World's Telephones.")
),
# Create a spot for the barplot
mainPanel(
plotOutput("phonePlot")
))
)
Shiny GalleryShiny Gallery










